package com.csy.admin.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.csy.admin.entity.ResourceUrl;
import com.csy.admin.mapper.ResourceUrlMapper;
import com.csy.admin.service.ResourceUrlService;
import com.csy.admin.util.PageUtils;
import com.csy.admin.util.Query;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  资源url实现类
 * </p>
 *
 * @author csy
 * @since 2018-09-17
 */
@Service
public class ResourceUrlServiceImpl extends ServiceImpl<ResourceUrlMapper, ResourceUrl> implements ResourceUrlService {

    /**
     * 获取资源url列表
     * @param params
     * @return
     */
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String name = (String) params.get("name");
        String classId = (String) params.get("classId");
        Boolean flag = true;
        if(StringUtils.isBlank(classId) || classId.equals("-1")){
            flag = false;
        }
        IPage<ResourceUrl> page = this.page(
                new Query<ResourceUrl>(params).getPage(),
                new QueryWrapper<ResourceUrl>().like(StringUtils.isNotBlank(name),"memo",name)
                .eq(flag,"class_id",classId)
        );
        return new PageUtils(page);
    }
}
